//
//  WPTabBarController.m
//  wobingwoyi
//
//  Created by WGP on 16/7/21.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPTabBarController.h"
#import "WPHomeViewController.h"
#import "WPReadingNavigationController.h"
#import "WPReadingViewController.h"
#import "WPMineViewController.h"
#import "WPMessageVC.h"
#import "WPMineNavigationController.h"
#import "WPBaseNavigationController.h"
#import "WPHomeNavigationController.h"
#import "WPMessagerNavigationController.h"

@interface WPTabBarController ()

@end

@implementation WPTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSubcontrollers];
    
    self.tabBar.translucent = NO;
    
}

-(void)setupSubcontrollers
{
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = GlobalColor;
    
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSForegroundColorAttributeName] = RGB_SAME(102);
    
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    
    [self addChildVC:[[WPHomeNavigationController alloc] initWithRootViewController:[WPHomeViewController new]] isNavigationController:YES title:@"首页" image:@"shouye" selectedImage:@"shouye_selected"];
    [self addChildVC:[[WPMessagerNavigationController alloc] initWithRootViewController:[WPMessageVC new]] isNavigationController:YES title:@"消息" image:@"shouye" selectedImage:@"shouye_selected"];
    [self addChildVC:[[WPReadingNavigationController alloc] initWithRootViewController:[WPReadingViewController new]] isNavigationController:YES title:@"阅读排名" image:@"read" selectedImage:@"read_selected"];
    [self addChildVC:[[WPMineNavigationController alloc] initWithRootViewController:[WPMineViewController new]] isNavigationController:YES title:@"我的" image:@"mine" selectedImage:@"mine_selected"];
}

-(void)addChildVC:(UIViewController *)vc isNavigationController:(BOOL)isNavigationController title:(NSString *)title image:(NSString *)imageName selectedImage:(NSString *)selectedName
{
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    
    UIImage *tempImage = [UIImage imageNamed:selectedName];
    UIImage *selectedImage = [tempImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = selectedImage;
    
    if (isNavigationController) {
        [self addChildViewController:vc];
        return ;
    }
    
    WPBaseNavigationController *bnc = [[WPBaseNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:bnc];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
